package com.talent.jiwen.util;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Html;

import com.talent.jiwen.base.App;

import java.net.URL;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;

/**
 * Created by qyqx on 2018/7/4.
 * 常量类
 */

public class Constant {

    public static final String APP_ID = "wxb57ee42c718af36a";//微信appId

    public static final String FORGET_PWD_CODE_METHOD = "1005";//重置密码
    public static final String REGISTER_CODE_METHOD = "1004";//账号注册
    public static final String LOGIN_WITH_CODE = "1008";//验证码登录


    public static final String TIKU_MIDDLE_GRADE = "6";//初中
    public static final String TIKU_PRIMARY_GRADE = "7";//小学

    public static final String TRAINING_NORMAL = "0";//普通训练
    public static final String TRAINING_STRONG = "1";//强化训练

    public static int PAY_SCENE_FOR_WX = 0;//微信付款类型，默认订单
    public static final int WX_PAY_FOR_ORDER = 0;//订单付款
    public static final int WX_PAY_FOR_RECHARGE = 1;//充值
    public static final int WX_PAY_FOR_DEPOSIT = 2;//缴纳保证金


    public static final LinkedHashMap<Integer , String> gradeMap = new LinkedHashMap<>();
    public static final LinkedHashMap<Integer , String> subjectMap = new LinkedHashMap<>();

    static {
        gradeMap.put(1 , "一年级");
        gradeMap.put(2 , "二年级");
        gradeMap.put(3 , "三年级");
        gradeMap.put(4 , "四年级");
        gradeMap.put(5 , "五年级");
        gradeMap.put(6 , "六年级");
        gradeMap.put(7 , "七年级");
        gradeMap.put(8 , "八年级");
        gradeMap.put(9 , "九年级");
        gradeMap.put(10 , "高一");
        gradeMap.put(11 , "高二");
        gradeMap.put(12 , "高三");


        subjectMap.put(1 , "语文");
        subjectMap.put(2 , "数学");
        subjectMap.put(3 , "英语");
        subjectMap.put(4 , "科学");
        subjectMap.put(5 , "物理");
        subjectMap.put(6 , "化学");
        subjectMap.put(7 , "生物");
        subjectMap.put(8 , "历史");
        subjectMap.put(9 , "地理");
        subjectMap.put(10 , "政治");

    }

    /**
     * @description 阿里云的url，用于拼接
     */
    public static final String ALIYUNURL = "http://xiaolanmao.oss-cn-hangzhou.aliyuncs.com/";

    public static String getAliyunurl(String pathName, String uuid) {
        return ALIYUNURL + uuid;
    }

    public static String getUUIDImageUrl(String pathName) {
        return UUID.randomUUID().toString().replaceAll("-", "") + "/" + pathName;
    }

    /**
     * @date 创建时间：2017/8/8
     * @author cmw
     * @description 获取文件名
     */

    public static String getPicNameFromPath(String picturePath) {
        String temp[] = picturePath.replaceAll("\\\\", "/").split("/");
        String fileName = "";
        if (temp.length > 1) {
            fileName = temp[temp.length - 1];
        }
        return fileName;
    }

    /**
     * @description list转化为以逗号隔开的字符串
     */
    public static String listToString(List<String> stringList) {
        if (stringList == null) {
            return null;
        }
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        for (String string : stringList) {
            if (flag) {
                result.append(",");
            } else {
                flag = true;
            }
            result.append(string);
        }
        return result.toString();
    }


    /**
     * @description 获取图片
     */
    public static Html.ImageGetter mImgGetFormNetwork = new Html.ImageGetter() {

        public Drawable getDrawable(String source) {
            Drawable drawable = null;
            URL url;
            try {
                url = new URL(source);
                drawable = Drawable.createFromStream(url.openStream(), "");  //获取网路图片
            } catch (Exception e) {
                return null;
            }

            drawable.setBounds(0, 0, drawable.getIntrinsicWidth() * 3, drawable.getIntrinsicHeight() * 3);
            return drawable;
        }
    };


    /**
     * @description 全局上下文
     */
    public static Context getContext() {
        return App.getInstance();
    }

}
